// pages/my/set/changePassWord/changePassWord.js
const app = getApp()
Page({
  data: {
    accountId:'',
    new:'',
    old:''
  },
  onLoad: function (options) {
    app.getMemInfo().then(res=>{
      this.setData({
        accountId:res.data.id
      })
    })
  },
  bindOld(e){
    this.setData({
      old:e.detail.value
    })
  },
  bindNew(e){
    this.setData({
      new:e.detail.value
    })
  },
  forgetPassWordTap(event){
    wx.navigateTo({
      url: '../../../index/forgetPassWord/forgetPassWord',
    })
  },
  bindChange(){
    if (this.data.old==''||this.data.new=='') {
      app.errorMsg('密码不能为空')
    }else{    
      let data = {
        oldPwd:this.data.old,
        newPwd:this.data.new,
        accountId:this.data.accountId
      }
      app.request('wx_app/password/change',data,'GET').then(res=>{
        console.log(res)
        if (res.code==1) {
          wx.showToast({
            title:'修改成功'
          })
          setTimeout(function(){
            wx.removeStorage({
              key:'memInfo',
              success(){
                wx.redirectTo({
                  url:'../../../index/index'
                })
              }
            })
          },1500)
        }else{
          app.errorMsg(res.message)
        }
      })
    }
  }
})